note
	description: "[
					Abstract notion of a {PHONE} where the precise type is not
					yet known (e.g. US Phone, international, cell, satelite, landline, etc.)
					]"
	date: "$Date: $"
	revision: "$Revision: $"

deferred class
	PHONE [V -> PHONE_VALIDATOR, F -> PHONE_FORMATTER]

feature {NONE} -- Initialization

	make_with_alpha (a_iso_number: attached like number_type_anchor)
			-- Initialize Current with `a_iso_number'
		deferred
		end

feature -- Access

	number: attached like number_type_anchor
			-- Identifier of Current.

	country_code: attached like number_type_anchor
			-- Country identifier of Current.

	trunk_code: attached like number_type_anchor
			-- Analagous to `country_code' for Current.
		do
			Result := country_code
		end

	iso_9995_8_number (a_string: attached like number_type_anchor): attached like number_type_anchor
			-- ISO/IEC 9995-8:2009 defines an assignment identical to E.161 of the
			--		26 letters A-Z to the number keys of a numeric keypad. The space
			--		character is not assigned.
		require
			valid_characters: across a_string as al_string all ("0123456789ABCDEFGHIJKLMNOPQRSTUVQXYZ#*").has (al_string.item) end
		do
			create Result.make_empty
			across a_string as al_string loop
				if al_string.item.is_digit then
					Result.append_character (al_string.item)
				elseif across ("ABC") as al_two some al_two.item.is_equal (al_string.item.as_upper) end then
					Result.append ("2")
				elseif across ("DEF") as al_two some al_two.item.is_equal (al_string.item.as_upper) end then
					Result.append ("3")
				elseif across ("GHI") as al_two some al_two.item.is_equal (al_string.item.as_upper) end then
					Result.append ("4")
				elseif across ("JKL") as al_two some al_two.item.is_equal (al_string.item.as_upper) end then
					Result.append ("5")
				elseif across ("MNO") as al_two some al_two.item.is_equal (al_string.item.as_upper) end then
					Result.append ("6")
				elseif across ("PQRS") as al_two some al_two.item.is_equal (al_string.item.as_upper) end then
					Result.append ("7")
				elseif across ("TUV") as al_two some al_two.item.is_equal (al_string.item.as_upper) end then
					Result.append ("8")
				elseif across ("WXYZ") as al_two some al_two.item.is_equal (al_string.item.as_upper) end then
					Result.append ("8")
				elseif al_string.item.is_equal ('*') then
					Result.append ("*")
				elseif al_string.item.is_equal ('#') then
					Result.append ("#")
				end
			end
			check has_at_least_ten_characters: Result.count > 9 end
			Result := Result.substring (1, 10)
		end

feature -- Status Report

	is_valid: BOOLEAN
			-- Is `number' valid for Current?
		do
			Result := validator.is_valid (number)
		end

	is_information: BOOLEAN
			-- Is `a_number' information number?
		do
			Result := validator.is_information (number)
		end

	is_emergency: BOOLEAN
			-- Is `a_number' emergency number?
		do
			Result := validator.is_emergency (number)
		end

	is_system_services: BOOLEAN
			-- Is `a_number' services number?
		do
			Result := validator.is_system_services (number)
		end

	is_directory_assistance: BOOLEAN
			-- Is `a_number' directory assistance ?
		do
			Result := validator.is_directory_assistance (number)
		end

	is_ficticious: BOOLEAN
			-- Is `a_number' ficticious ?
		do
			Result := validator.is_ficticious (number)
		end

feature -- Settings

	set_number (a_number: attached like number_type_anchor)
			-- Set `number' with `a_number'
		do
			number := a_number
		ensure
			number_set: number.same_string (a_number)
		end

feature {PHONE_VALIDATOR, PHONE_FORMATTER} -- Implementation: Type Anchors

	number_type_anchor: detachable STRING
			-- Data type anchor. DO NOT CALL!
		require
			do_not_call: False
		do
			Result := Void
		end

	check_digit_0, check_digit_1, check_digit_9: like number_type_anchor
			-- Constant for checking against a '0', '1' or '9' digit, anchored on `number_type_anchor'
		deferred
		end

feature {TEST_SET_HELPER} -- Implementation

	validator: V

	formatter: F

;note
	copyright: "Copyright (c) 2012-2012, Greater Atlanta User Group for Eiffel (GAUGE)"
	license: "GPL version 2 (see http://www.eiffel.com/licensing/gpl.txt)"
	licensing_options: "http://www.eiffel.com/licensing"
	copying: "[
			This file is part of the Greater Atlanta User Group for Eiffel (GAUGE), Eiffel Development Environment.
			
			GAUGE's Eiffel Development Environment is free
			software; you can redistribute it and/or modify it under
			the terms of the GNU General Public License as published
			by the Free Software Foundation, version 2 of the License
			(available at the URL listed under "license" above).
			
			GAUGE's Eiffel Development Environment is
			distributed in the hope that it will be useful, but
			WITHOUT ANY WARRANTY; without even the implied warranty
			of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
			See the GNU General Public License for more details.
			
			You should have received a copy of the GNU General Public
			License along with Eiffel Software's Eiffel Development
			Environment; if not, write to the Free Software Foundation,
			Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
		]"
	source: "[
			GAUGE
			Atlanta, GA
			Website http://www.atlantausergroups.com/group/gauge
		]"
end
